

import request from '@/utils/request'

// login( {username:'zs',  password: 123}  )
export const login = (  { username, password }  ) => {
  return request.post('/login', {
    // 对象的属性 来自于 接口文档
    //  username  password
    // username： username
    username,
    password
  })
}


// 获取侧边栏数据
export const getMenusApi = () => {
  return   request.get("/menus")
}




//   params  传递的params  必须是一个对象 
//   参数 必须和接口文档一致
//   getUserListApi( {  query: '',  pagenum:1, pagesize: 12})
export const getUserListApi = params => {
  //  {params} 这个 等价于 {params: params}  
  return request.get("/users", { params });
};



//新增用户api
// {username   password}
export const addUserApi = (data) => {
  return request({
    method: "POST",
    url: "/users",
    data,
  });
};

//根据id获取用户api
export const getUserByIdApi = id => {
  return request({
    url: `/users/${id}`,
    
  });
};

//根据id修改用户api
export const editUserByIdApi = (data) => {
  return request({
    method: "PUT",
    url: `/users/${data.id}`,
    data,
  });
};

//根据id删除用户api
export const delUserByIdApi = (id) => {
  return request({
    method: "DELETE",
    url: `/users/${id}`,
  });


};

export const editUserStateApi = (userinfo) => {
  return request({
    method: "PUT",
    url: `users/${userinfo.id}/state/${userinfo.mg_state}`,
  });
};
